package com.sun.springboot_mq1.config;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

/**新增了一个队列 QC,绑定关系如下,该队列不设置 TTL 时间
 * @author shkstart
 * @create 2021-10-25 10:50
 */
@Configuration
public class MsgTtlQueueConfig {
    public static final  String QUEUE_C="QC";
    public static final String Y_DEAD_LETTER_EXCHANGE = "Y";

    @Bean("queuec")
    public Queue queuec(){
        Map<String,Object> map=new HashMap<>(3);
        // 声明当前队列绑定的死信交换机
        map.put("x-dead-letter-exchange",Y_DEAD_LETTER_EXCHANGE);
        // 声明当前队列的死信路由 key
        map.put("x-dead-letter-routing-key","YD");
        return QueueBuilder.durable(QUEUE_C).withArguments(map).build();
    }
    @Bean
    public Binding queuedBindingC(@Qualifier("queuec") Queue queuec, @Qualifier("xExchange")DirectExchange xExchange ){
        return BindingBuilder.bind(queuec).to(xExchange).with("XC");
    }
}
